trigger mergeAccounts on Account (before delete,after delete) {
    
   
    Set<ID> loserAccounts= new Set<ID>();
   
    List<User> loserusers = new list<User>();
   
   If(Trigger.isbefore)
   {
      System.debug('before Trigger'+ Trigger.old);
      
      for( Account a : Trigger.old)
      {
            loserAccounts.add(a.ownerid);
            
      }
      loserusers=[select id,name,email,AccountId from User where Id in :loserAccounts];
      System.debug('*****'+loserusers);
      If(!loserusers.isEmpty())
      {
      for(User u : loserusers)
      {
            SingleEmailMessage.SentEmailtoUsers(u.email);
      }
      }
   
   }
   
  If(Trigger.isafter) 
  {
  
      System.debug('&&&&&&&&'+ Trigger.old);
      Account WinnerAccount=Trigger.old[0];
      
      User winneruser=[Select id,name,email,AccountId from User where Id=:WinnerAccount.ownerid];
      SingleEmailMessage.SentEmailtoUsers(winneruser.email);
   
  }

}